package com.rimi.lyingGoShoppingMall.controller;

import com.rimi.lyingGoShoppingMall.bean.User;
import com.rimi.lyingGoShoppingMall.commos.ResponseData;
import com.rimi.lyingGoShoppingMall.commos.Status;
import com.rimi.lyingGoShoppingMall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 61919
 * @date 2020/3/2
 */
@Controller
public class LoginController {

    @Autowired
    UserService userService;

    /**
     * 默认进入的页面
     */
    @GetMapping("/")
    public String openning(){
        return "login";
    }

    @GetMapping("/index")
    public String index() {
        return "index";
    }


    /**
     * 欢迎页面
     */
    @GetMapping("/welcome")
    public String welcome(){
        return "welcome";
    }

    @ResponseBody
    @PostMapping(value = "/login",produces = "application/json")
    public ResponseData login(User user) {
        boolean login = userService.login(user);
        return login ? ResponseData.onSuccess() : ResponseData.onFailed(Status.LOGIN_NOT_MATCHED);
    }

}
